package com.example.validate.controller;

import com.example.validate.dto.User;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by TJ on 2017/9/20.
 */
@RestController
public class MainController {



    @RequestMapping
    public User test(@Valid User user, BindingResult bindingResult){
//        System.out.println(user);
//        System.out.println(bindingResult);
//        List<ObjectError> allErrors = bindingResult.getAllErrors();
//        for (ObjectError error : allErrors) {
//            System.out.println(error);
//
//
//        }
        if (bindingResult.hasErrors()) {
            System.out.println(bindingResult.getAllErrors());
        }


        return user;
    }
}
